package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.RoomBean;
import com.project.mapper.IRoomMapper;
import com.project.mapper.IStuMapper;
import com.project.mapper.IToolMapper;
import com.project.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoomServiceImpl implements IRoomService {

    @Autowired
    private IRoomMapper mapper;

    @Autowired
    private IStuMapper stuMapper;

    @Autowired
    private IToolMapper toolMapper;
    @Override
    public List<RoomBean> findByGender(String gender) {
        return mapper.findByGender(gender);
    }

    @Override
    public PageInfo<RoomBean> findByItem(Integer pageNO, String address, String status, String canIn, String roomGender) {
        PageHelper.startPage(pageNO, 10);
        PageInfo<RoomBean> pageInfo = PageInfo.of(mapper.findByItem(address, status, canIn, roomGender));
        return pageInfo;
    }

    @Override
    public void addRoom(RoomBean room) {
        mapper.addRoom(room);
    }

    @Override
    public boolean delRoom(Integer roomId) {
        if (stuMapper.findStuNumByRoomId(roomId) != 0) {
            return false;
        }
        toolMapper.delByRoomId(roomId);
        mapper.delRoom(roomId);
        return true;
    }

    @Override
    public RoomBean findById(Integer roomId) {
        return mapper.findById(roomId);
    }
}
